<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class TestInfo extends MY_Controller {
	function __construct() { 
		parent::__construct();
		$this -> load -> model("Vertical_project_model");	
		$this -> load -> model("Vertical_project_kh_model");	

		$this -> load -> model("Horizontal_project_model");	
		$this -> load -> model("Horizontal_project_kh_model");	
	}



	//保存横向课题uuid
	function saveHorizontalData(){

		// $connar1['where'] = $this->sqlEscape('is_del=?? and status=?? and new_uuid is null', array(0,3));
		// $kh = $this->Vertical_project_kh_model->get_list_full($connar1);
		$sql = "SELECT kh.id khid,kh.number khnumber,kh.name khname,kh.is_end khend,h.id,h.number,h.name,h.is_end ,kh.new_uuid from db_horizontal_project_kh kh left JOIN db_horizontal_project h on h.number = kh.number and h.name = kh.name and h.is_end = kh.is_end where kh.`status` = 3 and kh.is_del = 0 and h.id is not null and kh.new_uuid is null;";
		$kh = $this->Vertical_project_kh_model->query($sql);
		$res=array();
		foreach($kh as $k=>$v){
			$upsql = "UPDATE db_horizontal_project_kh set new_uuid = 'hxkt_".$v['id']."' where id =  ".$v['khid'];
			$res[] = $this->Vertical_project_kh_model->execute($upsql);
		}

		exit("成功更新".count($res)."条横向课题数据");

	}


	//保存横向课题uuid
	function saveVerticallData(){

		// $connar1['where'] = $this->sqlEscape('is_del=?? and status=?? and new_uuid is null', array(0,3));
		// $kh = $this->Vertical_project_kh_model->get_list_full($connar1);
		$sql = "SELECT kh.id khid,kh.number khnumber,kh.name khname,kh.is_end khend,h.id,h.number,h.name,h.is_end ,kh.new_uuid from db_vertical_project_kh kh left JOIN db_vertical_project h on h.number = kh.number and h.name = kh.name and h.is_end = kh.is_end where h.id is not null and kh.new_uuid is null;";
		$kh = $this->Vertical_project_kh_model->query($sql);
		$res=array();
		foreach($kh as $k=>$v){
			$upsql = "UPDATE db_vertical_project_kh set new_uuid = 'zxkt_".$v['id']."' where id =  ".$v['khid'];
			$res[] = $this->Vertical_project_kh_model->execute($upsql);
		}

		exit("成功更新".count($res)."条纵向课题数据");

	}
}